package me.zhengjie.suli.dashboard.rest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.Log;
import me.zhengjie.annotation.rest.AnonymousGetMapping;
import me.zhengjie.annotation.rest.AnonymousPostMapping;
import me.zhengjie.suli.dashboard.service.DashboardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequiredArgsConstructor
@Api(tags = "首页仪表盘")
@RequestMapping("/api/dashboard")
public class DashboardController {
    @Autowired
    DashboardService dashboardService;

    @AnonymousGetMapping(value = "/getDataByType/{type}")
    @Log("首页仪表盘统计图")
    @ApiOperation("首页趋势图-大")
    public ResponseEntity<Object> getDataByType(@PathVariable("type") String type) {
        Map<String, List<Integer>> list = dashboardService.getDataByType(type);
        return new ResponseEntity<>(list, HttpStatus.OK);
    }

    @AnonymousGetMapping(value = "/getPieChartData")
    @Log("首页任务统计图")
    @ApiOperation("首页任务统计图")
    public ResponseEntity<Object> getPieChartData() {
        return new ResponseEntity<>(dashboardService.getPieChartData(), HttpStatus.OK);
    }

    @AnonymousGetMapping(value = "/getBarchartData")
    @Log("首页任务异常柱形图")
    @ApiOperation("首页任务异常柱形图")
    public ResponseEntity getBarchartData() {
        return new ResponseEntity(dashboardService.getBarchartData(), HttpStatus.OK);
    }

    @AnonymousGetMapping(value = "/getBarchartDataOutHouse")
    @Log("首页任务异常柱形图")
    @ApiOperation("首页任务异常柱形图")
    public ResponseEntity getBarchartDataOutHouse() {
        return new ResponseEntity(dashboardService.getBarchartDataOutHouse(), HttpStatus.OK);
    }

    @AnonymousGetMapping(value = "/getPieChartLocationData")
    @Log("首页库位统计图")
    @ApiOperation("首页库位统计图")
    public ResponseEntity getPieChartLocationData() {
        return new ResponseEntity(dashboardService.getBarchartLocationData(), HttpStatus.OK);
    }

    @AnonymousGetMapping(value = "/getTodayNumber")
    @Log("首页库位统计图")
    @ApiOperation("首页库位统计图")
    public ResponseEntity getTodayNumber() {
        return new ResponseEntity(dashboardService.getTodayNumber(), HttpStatus.OK);
    }

    @AnonymousGetMapping(value = "/getTimeNumber")
    @Log("首页库位统计图")
    @ApiOperation("首页库位统计图")
    public ResponseEntity getTimeNumber() {
        return new ResponseEntity(dashboardService.getTimeNumber(), HttpStatus.OK);
    }

    @AnonymousGetMapping(value = "/getOneWeekToAndOutData")
    @Log("一周出入库情况")
    @ApiOperation("一周出入库情况")
    public ResponseEntity getOneWeekToAndOutData() {
        return new ResponseEntity(dashboardService.getOneWeekToAndOutData(), HttpStatus.OK);
    }

    @AnonymousGetMapping(value = "/getTasks")
    @Log("获取任务列表")
    @ApiOperation("获取任务列表")
    public ResponseEntity getTasks() {
        return new ResponseEntity(dashboardService.getTasks(), HttpStatus.OK);
    }

    @AnonymousPostMapping(value = "/getInventory")
    @Log("首页获取库存信息")
    @ApiOperation("首页获取库存信息")
    public ResponseEntity getInventory(@RequestBody int pageNum) {
        return new ResponseEntity(dashboardService.getInventory2(pageNum), HttpStatus.OK);
    }

}
